﻿@{
    ViewBag.ParentUrl = "/Ticket/Index";
    ViewBag.Title = "分配发票次数";

    Core_User agent = ViewBag.Agent as Core_User;
    Core_User user = ViewBag.User as Core_User;
}
@section header{
    <style>
        .profile-info-name {
            width: auto;
        }
    </style>
}
@section breadcrumb
{
    <ul class="breadcrumb">
        <li>
            <i class="ace-icon fa fa-home home-icon"></i>
            <a href="/">首页</a>
        </li>
        <li class="active">@ViewBag.Title</li>
    </ul><!-- .breadcrumb -->
}

<div class="row">

    <div class="col-xs-12">

        <div class="widget-box">
            <div class="widget-header widget-header-flat">
                <h4 class="smaller">
                    <i class="icon-search"></i>
                    分配发票次数
                </h4>
            </div>

            <div class="widget-body">
                <div class="widget-main">
                    <div class="profile-user-info profile-user-info-striped">
                        <div class="profile-info-row">
                            <div class="profile-info-name"> 当前用户： </div>

                            <div class="profile-info-value">
                                @user.U_Name
                            </div>
                        </div>

                        <div class="profile-info-row">
                            <div class="profile-info-name"> 次数剩余： </div>

                            <div class="profile-info-value">
                                @user.U_InvoiceCount 次
                            </div>
                        </div>
                        <div class="profile-info-row">
                            <div class="profile-info-name"> 我的剩余次数： </div>

                            <div class="profile-info-value">
                                @agent.U_InvoiceCount 次
                            </div>
                        </div>
                        <div class="profile-info-row">
                            <div class="profile-info-name"> 分配次数： </div>

                            <div class="profile-info-value">
                                <input type="number" class="input-large" placeholder="次数" id="invoice" name="invoice"/>次
                            </div>
                        </div>
                    </div>

                </div>
            </div>
        </div>


        <div class="widget-box">
            <div class="widget-header widget-header-flat">
                <h4 class="smaller">
                    <i class="icon-search"></i>
                    分配票号次数
                </h4>
            </div>

            <div class="widget-body">
                <div class="widget-main">
                    <div class="profile-user-info profile-user-info-striped">
                        <div class="profile-info-row">
                            <div class="profile-info-name"> 当前用户： </div>

                            <div class="profile-info-value">
                                @user.U_Name
                            </div>
                        </div>

                        <div class="profile-info-row">
                            <div class="profile-info-name"> 票号剩余： </div>

                            <div class="profile-info-value">
                                @user.U_InterfaceCount 次
                            </div>
                        </div>
                        <div class="profile-info-row">
                            <div class="profile-info-name"> 我的剩余次数： </div>

                            <div class="profile-info-value">
                                @agent.U_InterfaceCount 次
                            </div>
                        </div>
                        <div class="profile-info-row">
                            <div class="profile-info-name"> 分配次数： </div>

                            <div class="profile-info-value">
                                <input type="number" class="input-large" placeholder="次数" id="interface" name="interface"/>次
                            </div>
                        </div>
                        <div class="profile-info-row">
                            <div class="profile-info-name"> 备注： </div>

                            <div class="profile-info-value">
                                <textarea cols="30" rows="5" id="memo" name="memo"></textarea>
                            </div>
                        </div>
                    </div>

                </div>
            </div>
        </div>

        <div class="space-4"></div>

        <div class="clearfix form-actions">
            <div class="col-md-offset-3 col-md-9">
                <button class="btn btn-info" type="submit" id="btnSubmit">
                    <i class="ace-icon fa fa-check bigger-110"></i>
                    修改并保存
                </button>

                &nbsp; &nbsp;
                <button class="btn" type="reset">
                    <i class="ace-icon fa fa-undo bigger-110"></i>
                    重置
                </button>
            </div>
        </div>
        <div class="hr hr-24"></div>

    </div>
</div>

@section footer{
    <script>
        $(function() {
            $('#btnSubmit').click(function() {
                var agentinterface = @agent.U_InterfaceCount
                var agentinvoice = @agent.U_InvoiceCount
                var uid = @user.U_Id

                var uinterface = $('#invoice').val();
                var uinvoice = $('#invoice').val();
                var memo = $('#memo').val();
                
                if (uinterface == '') {
                    alert('分配发票次数不能为空');
                    return false;
                }
                if (uinterface == '') {
                    alert('分配发票次数不能为空');
                    return false;
                }

                if (parseInt(uinvoice) > agentinvoice) {
                    alert('分配发票次数不足');
                    return false;
                }
                if (parseInt(uinterface) > agentinterface) {
                    alert('分配票号次数不足');
                    return false;
                }

                $.post("/ticket/allot", { uinterface: uinterface, uinvoice: uinvoice, uid: uid, memo: memo }, function(o) {
                    alert(o);
                });
            });
        });
    </script>
}